home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / book / src / main.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  5KB  |  215 lines

  1. /*
  2.  *            <<< ひみつのBook >>>
  3.  *
  4.  *      High Speed Text Viewer for FM-TOWNS
  5.  *
  6.  *  presented by MIYAZAKI & sugi  1990,91,92,93
  7. */
  8.  
  9. #include    <stdio.h>
  10. #include    <stdlib.h>
  11. #include    <string.h>
  12. #include    <ctype.h>
  13. #include    <egb.h>
  14. #include    <mos.h>
  15. #include    <fmc.h>
  16. #include    <msdos.cf>
  17. #include    <system.cf>
  18. #include    "menu_evt.h"
  19. #include    "init.h"
  20. #include    "book.h"
  21. #include    "lib.h"
  22. #include    "doslib.h"
  23. #include    "snd.h"
  24. #include    "keyio.h"
  25. #include    "cons.h"
  26. #include    "mouse.h"
  27. #ifdef VSYNC
  28. # include   "vsync.h"
  29. #endif
  30.  
  31.  
  32. /*  外部ファイルにあるルーチン  */
  33. extern  void    dsp_main(char *file);   /*  テキスト表示のメイン  */
  34. extern  void    set_vector(void);       /*  ハードエラーベクタの設定  */
  35. extern  void    reset_vector(void);     /*  ハードエラーベクタの復帰  */
  36.  
  37. extern  char   *param(char *path);      /*  パラメータのディレクトリに移動  */
  38.  
  39. static  char   moswork[MosWorkSize];    /*  mouseライブラリ用  */
  40. static  char   sndwork[SndWorkSize];    /*  snd  ライブラリ用  */
  41.         char   *config  = NULL;         /*  BOOK.CFG  */
  42.  
  43. const   cct[] =     /*  色テーブル  */
  44. {
  45.     0x00000000, 0x11111111, 0x22222222, 0x33333333,
  46.     0x44444444, 0x55555555, 0x66666666, 0x77777777,
  47.     0x88888888, 0x99999999, 0xAAAAAAAA, 0xBBBBBBBB,
  48.     0xCCCCCCCC, 0xDDDDDDDD, 0xEEEEEEEE, 0xFFFFFFFF
  49. };
  50.  
  51. void    _mwcall_onexit_fcns(void)
  52. {
  53.     /*  atexit() を使わない  */
  54. }
  55.  
  56.  
  57. int     main(int argc, char *argv[])
  58. {
  59. int     i;
  60. char    *file = NULL;
  61. char    *p;
  62. char    crrdir[256];
  63.  
  64.     /*  パラメータとオプションの解釈  */
  65.     for (i = 1; i < argc; i++)
  66.     {
  67.         p = argv[i] ;
  68.  
  69.         if (*p == '/' || *p == '-')
  70.         {
  71.             p++;
  72.             switch (toupper(*p))
  73.             {
  74.               case 'C':         /*  BOOK.CFG の位置  */
  75.                 if (*(p+1) != '\0')
  76.                     config = p+1;
  77.                 goto next;
  78.  
  79.               case 'V':         /*  version  */
  80.                 _strcats(80, crrdir, "book.exp v",
  81.                         _version, " / ", date, " / ", timestamp, "\n", NULL);
  82.                 write(1, crrdir, strlen(crrdir));
  83.                 exit(0);
  84.             }
  85.         }
  86.         else
  87.             file = p;
  88. next:   continue;
  89.     }
  90.  
  91.     /*  致命的エラー割り込みの再設定  */
  92.     set_vector();
  93.  
  94.     /*  BOOK.EXP のパスリストを作成  */
  95.     strcpy(crrdir, argv[0]);
  96.     if ((p = jstrrchr(crrdir, '\\')) == NULL &&
  97.         (p = strchr(crrdir, ':')) == NULL)
  98.         crrdir[0] = '\0';
  99.     else
  100.         *++p = '\0';
  101.  
  102.     /*  コンフィグファイルを読む  */
  103.     if (config == NULL &&
  104.         (config = (char *)malloc( strlen(crrdir) + 16)) != NULL)
  105.     {
  106.         strcpy(config, crrdir);
  107.         strcat(config, CONFIG_FILE);
  108.     }
  109.     if (config != NULL)
  110.         configuration(config);
  111.  
  112.     /*  指定されていない場合の onsei.dic のフルパス作成  */
  113.     if (setup.onsei_dic == NULL &&
  114.         (setup.onsei_dic = (char *)malloc(strlen(crrdir) + 16)) != NULL)
  115.     {
  116.         strcpy(setup.onsei_dic, crrdir);
  117.         strcat(setup.onsei_dic, ONSEI_DIC);
  118.     }
  119.  
  120.     /*  起動時のカレント・ディレクトリを退避  */
  121.     getdir(crrdir);
  122.     if ((p = jstrrchr(crrdir, '\\')) != NULL && strlen(crrdir) > 3)
  123.         *p = '\0';      /*  余計な \ をつぶす  */
  124.     chdrv(*crrdir - 'A');
  125.  
  126.     /*  オプションによるファイル指定は特別処理  */
  127.     if ((p = param(file)) != NULL)
  128.         file = p;
  129.  
  130.     /*  画面の初期化  */
  131.     EGB_init(gwork, EgbWorkSize);
  132.  
  133.     setup.palette.text2 = setup.palette.text;
  134.     setup.palette.text2.color = 2;
  135.     init_screen();
  136.  
  137. #ifdef VSYNC
  138.     /* VSYNC割り込みライブラリの初期化 */
  139.     VSYNC_init();
  140. #endif
  141.     SND_init(sndwork);
  142.     SND_elevol_mute(0x33);
  143.  
  144.     /*  マウスの初期化  */
  145.     MOS_start(moswork, MosWorkSize);
  146.     MOS_resolution(0, 3);
  147.     MOS_resolution(1, 3);
  148.     MOS_writePage(1);
  149.     MOS_horizon(MIN_HORIZON, (max_horizon = MAX_HORIZON2));
  150.     MOS_vertical(MIN_VERTICAL, MAX_VERTICAL);
  151.  
  152.     mos_ptn_init();
  153.     set_mos_ptn(MOSCSR_FINGER);
  154.     MOS_disp(MOS_ON);
  155.  
  156.     ctblset(_CHR_COL, _BAK_COL);
  157.  
  158. #ifdef VSYNC
  159. #else
  160.     /*  FM音源割り込みの準備  */
  161.     SND_fm_timer_a_set(0, 1);
  162. #endif
  163.  
  164.     /*  キーボードアサインの保存  */
  165.     kb_asign_push();
  166.  
  167.     /*  キーアドレス変換テーブルの準備  */
  168.     kb_setup_cnvtbl();
  169.  
  170.     /*  かな漢字変換使用宣言  */
  171.     KAN_start();
  172.  
  173.     /*  ONSEI.DIC の読み込み  */
  174.     if (init_tree(setup.onsei_dic) != ERR)
  175.         can_use_snd = TRUE;
  176.  
  177.     /*  Main Loop を呼ぶ  */
  178.     dsp_main(file);
  179.  
  180.     /*  画面サイズの再設定  */
  181.     wide_screen(OFF);
  182.     vertical_screen(480);
  183.  
  184.     /*  かな漢字変換終了宣言  */
  185.     KAN_end();
  186.  
  187.     /*  キーボードアサインの復元  */
  188.     kb_asign_pop();
  189.  
  190.     /*  マウスとサウンドの終了宣言  */
  191.     MOS_end();
  192.     SND_elevol_mute(0x00);
  193.     SND_end();
  194.  
  195. #ifdef VSYNC
  196.     /* VSYNC割り込みライブラリの終了 */
  197.     VSYNC_end();
  198. #else
  199.     /*  FM音源割り込みの終了  */
  200.     SND_fm_timer_a_set(0, 1);
  201. #endif
  202.  
  203.     /*  起動時のカレント・ディレクトリへ復帰  */
  204.     chdrv(crrdir[0] - 'A');
  205.     chdir(crrdir);
  206.  
  207.     /*  致命的エラー割り込みの再設定  */
  208.     reset_vector();
  209.  
  210.     return 0;
  211. }
  212.  
  213.  
  214.  
  215.